// pages/leaveWord/leaveWord.js
var request = require("../../utils/request.js");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    noteMaxLen: 100,//备注最多字数
    info: "",
    noteNowLen: 0,//备注当前字数,
    textarea: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;

  },
  // 提交数据
  getData: function () {
    var that = this;
    wx.request({
      url: request.dataUrl + '/api/user/post_opi',
      data: {
        session3rd: wx.getStorageSync('session3rd'),
        content: that.data.textarea
      },
      header: {},
      method: 'POST',
      success: function (res) {
        console.log(res)
        if (res.data.code == 0) {
          wx.showToast({
            title: '留言成功',
            duration: 1500,
            image:'../../image/success.png',            
            success: function () {
              that.setData({
                info: '',
                noteNowLen: 0
              })
            },
          })

        }else{
          wx.showToast({
            title: '留言失败',
            duration: 1500,
            image: '../../image/fail.png',
            success: function () {
              that.setData({
                info: '',
                noteNowLen: 0
              })
            },
          })
        }


      }

    })

  },
  bindTextAreaChange: function (e) {
    var that = this
    var value = e.detail.value
    var len = parseInt(value.length);
    if (len > that.data.noteMaxLen) return;
    that.setData({
      info: value,
      noteNowLen: len
    })
  },
  //提交数据
  formSubmit(e) {
    var that = this;
    console.log(e.detail.value.textarea)

    that.setData({
      textarea: e.detail.value.textarea
    })
    that.getData();

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})